package com.example.mytestdemo.scroll

import android.util.Log
import android.view.View
import com.example.mytestdemo.BaseViewBindActivity
import com.example.mytestdemo.R
import com.example.mytestdemo.databinding.ActivityAppbarUserLayoutBinding
import com.google.android.material.appbar.AppBarLayout

/**
 *
 * 你是一个专业的Android 开发工程师善于使用CoordinatorLayout ，
 * 现在有4个布局前三个都是linearlayout，第四个是recycleview
 * 现在要求滑动recycleview的时候第一个和第三个linearlayout跟随滑动隐藏，
 * 第二个linearlayout置顶后不会跟随滑动
 */
class AppbarUseActivity : BaseViewBindActivity<ActivityAppbarUserLayoutBinding>() {
    override fun getLayoutInflateId(): Int {
        return R.layout.activity_appbar_user_layout
    }

    override fun initData() {

        mBind.appbar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
            Log.d(TAG, "initDataverticalOffset : $verticalOffset")
            if (Math.abs(verticalOffset)<=300) {


                mBind.llSecond.translationY = 300+verticalOffset.toFloat()
//           val layoutParams = mBind.llSecond.layoutParams as FrameLayout.LayoutParams
//
//            layoutParams.setMargins(0,300+verticalOffset,0,0)
//            mBind.llSecond.layoutParams = layoutParams

//                val layoutParams1 = mBind.topToolbar.layoutParams as LinearLayout.LayoutParams
//            layoutParams1.setMargins(0,600+verticalOffset,0,0)
//            mBind.topToolbar.layoutParams = layoutParams1
//
            }else{
                mBind.llSecond.translationY = 0f

            }


//            val layoutParams1 = mBind.topToolbar.layoutParams as CollapsingToolbarLayout.LayoutParams
//            layoutParams1.setMargins(0,600+verticalOffset,0,0)
//            mBind.topToolbar.layoutParams = layoutParams1
        })

        mBind.bt1.setOnClickListener {
            mBind.collapsBar.minimumHeight = 300
            mBind.ll1.visibility = View.VISIBLE
            mBind.llSecond.visibility = View.VISIBLE
            mBind.ll3.visibility = View.VISIBLE
            mBind.viewHead.visibility = View.VISIBLE
        }

        mBind.bt2.setOnClickListener {
            mBind.collapsBar.minimumHeight = 300
            mBind.ll1.visibility = View.VISIBLE
            mBind.llSecond.visibility = View.VISIBLE
            mBind.ll3.visibility = View.GONE
            mBind.viewHead.visibility = View.VISIBLE
        }

        mBind.bt3.setOnClickListener {
            mBind.collapsBar.minimumHeight = 0

            mBind.ll1.visibility = View.VISIBLE
            mBind.llSecond.visibility = View.GONE
            mBind.ll3.visibility = View.GONE
            mBind.viewHead.visibility = View.GONE

        }
    }

    override fun initUI() {
    }

}